/// <summary>
        /// Initializes the <see cref="AnonymousMetaType"/>.
        /// </summary>
        /// <param name="memberInfo">The <see cref="Type"/> to generate the <see cref="AnonymousMetaType"/> from.</param>
        public override void Initialize(MemberInfo memberInfo)
        {
#if !NETFX_CORE
            Type representedType = memberInfo as Type;
#else
            Type representedType = ((TypeInfo)memberInfo).AsType();
#endif
            if (representedType == null)
            {
                throw new ArgumentException("Not of Type 'Type'", "memberInfo");
            }
            Name = representedType.Name;
#if !NETFX_CORE
            foreach (PropertyInfo property in representedType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty))
#else
            foreach (PropertyInfo property in ((TypeInfo)memberInfo).DeclaredProperties)
#endif
            {
                MetaProperties.Add(new AnonymousMetaProperty(property));
            }

            //The represented type is set here, transfered to the Server as String,
            //recreated with the same name, and taken back with getType()
            RepresentedType = representedType;
        }
        /// <summary>
        /// Serves as a hash function for a particular type.
        /// </summary>
        /// <returns>A hash code for the current <see langword="object"/>.</returns>
        public override int GetHashCode()
        {
            int num = 51463360;

            MetaProperties.ForEach(o => num ^= EqualityComparer <AnonymousMetaProperty> .Default.GetHashCode(o));
            return(num ^ base.GetHashCode());
        }
Esempio n. 3
0
        private static bool GetCustomSharePointProperty(Document document, string propertyName, out string returnValue)
        {
            try
            {
                MetaProperties metadataProps = document.ContentTypeProperties;
                //this will error if there are no sharepoint properties. No way around this.

                if (((metadataProps != null)))
                {
                    foreach (MetaProperty prop in metadataProps)
                    {
                        if (String.Equals(prop.Name, propertyName, StringComparison.OrdinalIgnoreCase))
                        {
                            if (((prop.Value != null)))
                            {
                                returnValue = prop.Value.ToString().ToLower();
                                return(true);
                            }
                        }
                    }
                }
            }
// ReSharper disable EmptyGeneralCatchClause
            catch //supress all errors as ContentTypeProperties generates too many errors on startup.
// ReSharper restore EmptyGeneralCatchClause
            {
            }
            returnValue = string.Empty;
            return(false);
        }
Esempio n. 4
0
        /// <summary>
        /// Overrides the equality comparision.
        /// </summary>
        /// <param name="obj">Other object to compare with.</param>
        /// <returns>True, if the other <see langword="object"/> is equal to this. False, if not.</returns>
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            if (!base.Equals(obj))
            {
                return(false);
            }
            AnonymousMetaType other = (AnonymousMetaType)obj;

            if (MetaProperties.Count != other.MetaProperties.Count)
            {
                return(false);
            }
            return(!MetaProperties.Where((t, i) => !t.Equals(other.MetaProperties[i])).Any());
        }
        /// <summary>
        /// Generate the a clr type at runtime.
        /// </summary>
        /// <returns>Returns the generated <see cref="Type"/>.</returns>
        private Type GenerateAnonymousType(ModuleBuilder dynamicTypeModule)
        {
            TypeBuilder dynamicType = dynamicTypeModule.DefineType(string.Concat(Name, Guid.NewGuid()), TypeAttributes.NotPublic | TypeAttributes.Sealed | TypeAttributes.Class | TypeAttributes.BeforeFieldInit);

            GenericTypeParameterBuilder[] typeParameters = dynamicType.DefineGenericParameters(GenericClassParameterNames.ToArray());

            string[]            fieldNames    = FieldNames.ToArray();
            List <FieldBuilder> createdFields = new List <FieldBuilder>();

            for (int i = 0; i < fieldNames.Length; i++)
            {
                FieldBuilder           field         = dynamicType.DefineField(fieldNames[i], typeParameters[i], FieldAttributes.Private | FieldAttributes.InitOnly);
                Type                   attributeType = typeof(DebuggerBrowsableAttribute);
                CustomAttributeBuilder attribute     = new CustomAttributeBuilder(attributeType.GetConstructor(new[] { typeof(DebuggerBrowsableState) }), new object[] { DebuggerBrowsableState.Never });
                field.SetCustomAttribute(attribute);
                createdFields.Add(field);
            }
            string[] propertyNames = PropertyNames.ToArray();
            List <PropertyBuilder> createdProperties = new List <PropertyBuilder>();

            for (int i = 0; i < propertyNames.Length; i++)
            {
                PropertyBuilder property = GenerateProperty(dynamicType, propertyNames[i], createdFields[i]);
                createdProperties.Add(property);
            }

            GenerateClassAttributes(dynamicType, propertyNames);

            GenerateConstructor(dynamicType, propertyNames, createdFields);
            GenerateEqualsMethod(dynamicType, createdFields.ToArray());
            GenerateGetHashCodeMethod(dynamicType, createdFields.ToArray());
            GenerateToStringMethod(dynamicType, propertyNames, createdFields.ToArray());

            Type createdType = dynamicType.CreateType();

            return(createdType.MakeGenericType(MetaProperties.Select(
                                                   p => (Type)p.PropertyType.GetClrVersion()
                                                   ).ToArray()));
        }
 /// <summary>
 /// Indicate the MetaProperties at the position equals a specified MetaProperties
 /// </summary>
 /// <param name="meta">A MetaProperties value</param>
 /// <returns>True if the MetaProperties at the position equals the specified MetaProperties, else false.</returns>
 public bool VerifyMetaProperty(MetaProperties meta)
 {
     return !this.IsEndOfStream && this.Verify((uint)meta, 0);
 }
Esempio n. 7
0
        public void Generate()
        {
            // Verify and add path to meta property cache
            for (int i = 0; i < Path.Nodes.Length; i++)
            {
                for (int j = Path.Nodes[i].Top; j <= Path.Nodes[i].Bottom; j++)
                {
                    var mp  = (MetaProperty)Path.Nodes[i].Block.Members[j];
                    var loc = new MetaLocation(i, j);

                    MetaLocation ploc;
                    if (MetaProperties.TryGetValue(mp.Name, out ploc))
                    {
                        var pmp = GetProperty(ploc);


                        // TODO: This is not correct
                        if (!pmp.ReturnType.Equals(mp.ReturnType))
                        {
                            Log.Error(mp.Source, ErrorCode.E5000, mp.Name.Quote() + " does not have the same type as the previous declaration at " + pmp.Source + " when exposed from " + Path.Quote() + " at " + Path.Source);
                        }

                        PrevProperties.Add(loc, ploc);
                    }

                    MetaProperties[mp.Name] = loc;
                }
            }

            // Resolve terminal properties
            foreach (var tp in Backend.ShaderBackend.OutputProperties)
            {
                MetaLocation loc;
                if (!MetaProperties.TryGetValue(tp.Name, out loc))
                {
                    Log.Error(Path.Source, ErrorCode.I5001, "Terminal property " + tp.Name.Quote() + " was not found in " + Path.Quote());
                    continue;
                }

                var mp = GetProperty(loc);
                var dt = ILFactory.GetType(Path.Source, tp.TypeString);

                if (!mp.ReturnType.Equals(dt))
                {
                    Log.Error(Path.Source, ErrorCode.I5001, "Terminal property " + tp.Name.Quote() + " was found with type " + mp.ReturnType.Quote() + " when " + dt.Quote() + " was expected");
                    continue;
                }

                var sym = ProcessMetaProperty(loc, tp.Required);
                if (sym.Value == null)
                {
                    continue;
                }

                LocationStack.Add(loc);

                switch (tp.Stage)
                {
                case MetaStage.Vertex:
                    sym = ProcessStage(sym, MetaStage.Vertex, MetaStage.Vertex);
                    DrawState.VertexShader.Terminals[tp.Name] = sym.Value;
                    break;

                case MetaStage.Pixel:
                    sym = ProcessStage(sym, MetaStage.Pixel, MetaStage.Pixel);
                    DrawState.PixelShader.Terminals[tp.Name] = sym.Value;
                    break;

                default:
                    sym = ProcessStage(sym, MetaStage.Volatile, MetaStage.Volatile);
                    DrawState.Terminals[tp.Name] = sym.Value;
                    break;
                }

                LocationStack.RemoveLast();
            }

            if (!DrawState.Terminals.ContainsKey("VertexCount"))
            {
                var loc = MetaProperties["VertexCount"];
                var mp  = GetProperty(loc);

                if (DetectedVertexCounts.Count == 1)
                {
                    LocationStack.Add(loc);

                    var fc = new FunctionCompiler(Compiler, IL);
                    DrawState.Terminals["VertexCount"] = fc.CompileImplicitCast(DetectedVertexCounts[0].Value.Source, mp.ReturnType, ProcessStage(DetectedVertexCounts[0], MetaStage.Volatile, MetaStage.Volatile).Value);

                    LocationStack.RemoveLast();
                }
                else
                {
                    Log.Error(CreateTrace(mp, loc, null), ErrorCode.E5002, "Unable to auto detect 'VertexCount' in " + Path.Quote());
                }
            }

            MetaPropertyEmitter.Emit(this);

            ShaderProcessor.ProcessShader(this, DrawState.VertexShader);
            ShaderProcessor.ProcessShader(this, DrawState.PixelShader);

            ProcessStructs();

            var p = new IndirectionTransform(Compiler.Pass);

            DrawState.VertexShader.Visit(p);
            DrawState.PixelShader.Visit(p);
        }
Esempio n. 8
0
		public MetaModel()
		{
			PropertyAccessor = new PropertyAccessor();
			MetaProperties = new MetaProperties();
		}
Esempio n. 9
0
 /// <summary>
 /// Read a MetaProperties value from stream,
 /// and advance the position within the stream by 4,
 /// compare it to the desired MetaProperties
 /// </summary>
 /// <param name="meta">The desired Markers</param>
 /// <returns>If read value equals the desired Markers return true, else false.</returns>
 public bool ReadMetaProperty(MetaProperties meta)
 {
     return(this.ReadUInt32() == (uint)meta);
 }
Esempio n. 10
0
 /// <summary>
 /// Indicate the MetaProperties at the position equals a specified MetaProperties
 /// </summary>
 /// <param name="meta">A MetaProperties value</param>
 /// <returns>True if the MetaProperties at the position
 /// equals the specified MetaProperties,
 /// else false.
 /// </returns>
 public bool VerifyMetaProperty(MetaProperties meta)
 {
     return(!this.IsEndOfStream && this.Verify((uint)meta, 0));
 }
 /// <summary>
 /// Indicate whether a MetaProperties is an end marker.
 /// </summary>
 /// <param name="marker">The Markers.</param>
 /// <returns>If a Markers is an end marker, return true, else false.</returns>
 public static bool IsEndMarker(MetaProperties marker)
 {
     List<MetaProperties> markers = GetEnumValues<MetaProperties>();
     return markers.Contains(marker);
 }
Esempio n. 12
0
        /// <summary>
        /// Indicate whether a MetaProperties is an end marker.
        /// </summary>
        /// <param name="marker">The Markers.</param>
        /// <returns>If a Markers is an end marker, return true, else false.</returns>
        public static bool IsEndMarker(MetaProperties marker)
        {
            List <MetaProperties> markers = GetEnumValues <MetaProperties>();

            return(markers.Contains(marker));
        }
 /// <summary>
 /// Read a MetaProperties value from stream,
 /// and advance the position within the stream by 4,
 /// compare it to the desired MetaProperties
 /// </summary>
 /// <param name="meta">The desired Markers</param>
 /// <returns>If read value equals the desired Markers return true, else false.</returns>
 public bool ReadMetaProperty(MetaProperties meta)
 {
     return this.ReadUInt32() == (uint)meta;
 }