public void BindAttribute(string nameInShader, string attributeName, System.Object obj) { BoundAttribute a = new BoundAttribute(); a.nameInShader = nameInShader; a.attributeName = attributeName; a.boundObject = obj; a.info = obj.GetType().GetField(attributeName); bool replaced = false; int id = 0; foreach (BoundAttribute ba in boundAttributes) { if (ba.nameInShader == nameInShader) { boundAttributes[id] = a; DebugThis(ba.nameInShader + " is being rebound"); replaced = true; break; } id++; } if (replaced == false) { boundAttributes.Add(a); } }
public void BindAttribute(string nameInShader, string attributeName, System.Object obj) { BoundAttribute a = new BoundAttribute(); a.nameInShader = nameInShader; a.attributeName = attributeName; a.boundObject = obj; a.info = obj.GetType().GetField(attributeName); boundAttributes.Add(a); }
private static void InvokeField(object instance, MemberInfo member, BoundAttribute boundAttribute) { if (member.MemberType != MemberTypes.Field) { return; } var fieldInfo = member as FieldInfo; SetValue(instance, BindingCache.CacheMemberBinding(instance, member, boundAttribute, fieldInfo.FieldType, FieldBindingFlags)); }
private static void InvokeProperty(object instance, MemberInfo member, BoundAttribute boundAttribute) { if (member.MemberType != MemberTypes.Property) { return; } var propertyInfo = member as PropertyInfo; var type = propertyInfo.PropertyType; SetValue(instance, BindingCache.CacheMemberBinding(instance, member, boundAttribute, type, PropertyBindingFlags)); }
public void BindAttribute(string nameInShader, string type, string attributeName, System.Object obj) { BoundAttribute a = new BoundAttribute(); a.nameInShader = nameInShader; a.shaderType = type; a.attributeName = attributeName; a.boundObject = obj; boundAttributes.Add(a); }
private static InvocationInfo CreateInvocationInfo(MemberInfo member, BoundAttribute boundAttribute, Type type, BindingFlags bindingFlags) { return new InvocationInfo { Name = member.Name, BoundTo = boundAttribute.BoundTo, Scope = boundAttribute.ScopeContext, MemberInfo = member, MemberType = type, Binding = bindingFlags, ResolverContext = boundAttribute.ResolverContext, SetExpression=TypeExtensions.BuildSetAccessor(member) }; }
private static InvocationInfo CreateInvocationInfo(MemberInfo member, BoundAttribute boundAttribute, Type type, BindingFlags bindingFlags) { return(new InvocationInfo { Name = member.Name, BoundTo = boundAttribute.BoundTo, Scope = boundAttribute.ScopeContext, MemberInfo = member, MemberType = type, Binding = bindingFlags, ResolverContext = boundAttribute.ResolverContext, SetExpression = TypeExtensions.BuildSetAccessor(member) }); }
internal static InvocationInfo CacheMemberBinding(object instance, MemberInfo member, BoundAttribute boundAttribute, Type type, BindingFlags bindingFlags) { var cache = InvocationCache[instance.GetType()]; InvocationInfo info; if (!cache.TryGetValue(member.Name,out info)) { lock (InvocationCache) { var invocationInfo = CreateInvocationInfo(member, boundAttribute, type, bindingFlags); if (!cache.TryGetValue(member.Name, out info)) cache.Add(member.Name, invocationInfo); return invocationInfo; } } return info; }
public bool TryParseEventCallbackTypeArgument(out string argument) { // This is ugly and ad-hoc, but for various layering reasons we can't just use Roslyn APIs // to parse this. We need to parse this just before we write it out to the code generator, // so we can't compute it up front either. if (BoundAttribute == null || !BoundAttribute.IsEventCallbackProperty()) { throw new InvalidOperationException("This attribute is not an EventCallback attribute."); } if (string.Equals(TypeName, ComponentsApi.EventCallback.FullTypeName, StringComparison.Ordinal)) { // Non-Generic argument = null; return(false); } if (TypeName != null && TypeName.Length > ComponentsApi.EventCallback.FullTypeName.Length + "<>".Length && TypeName.StartsWith(ComponentsApi.EventCallback.FullTypeName, StringComparison.Ordinal) && TypeName[ComponentsApi.EventCallback.FullTypeName.Length] == '<' && TypeName[TypeName.Length - 1] == '>') { // OK this is promising. // // Chop off leading `...EventCallback<` and let the length so the ending `>` is cut off as well. argument = TypeName.Substring(ComponentsApi.EventCallback.FullTypeName.Length + 1, TypeName.Length - (ComponentsApi.EventCallback.FullTypeName.Length + "<>".Length)); return(true); } // If we get here this is a failure. This should only happen if someone manages to mangle the name with extensibility. // We don't really want to crash though. argument = null; return(false); }
internal static InvocationInfo CacheMemberBinding(object instance, MemberInfo member, BoundAttribute boundAttribute, Type type, BindingFlags bindingFlags) { var cache = InvocationCache[instance.GetType()]; InvocationInfo info; if (!cache.TryGetValue(member.Name, out info)) { lock (InvocationCache) { var invocationInfo = CreateInvocationInfo(member, boundAttribute, type, bindingFlags); if (!cache.TryGetValue(member.Name, out info)) { cache.Add(member.Name, invocationInfo); } return(invocationInfo); } } return(info); }